home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2007 January, February, March & April
/
Chip-Cover-CD-2007-02.iso
/
Pakiet bezpieczenstwa
/
mini Pentoo LiveCD 2006.1
/
mpentoo-2006.1.iso
/
livecd.squashfs
/
usr
/
lib
/
python2.4
/
site-packages
/
impacket
/
ntlm.pyc
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2006-06-30
|
9KB
|
181 lines
# Source Generated with Decompyle++
# File: in.pyc (Python 2.4)
from impacket.structure import Structure
try:
from Crypto.Cipher import DES
from Crypto.Hash import MD4
POW = None
except Exception:
try:
import POW
except Exception:
pass
except:
None<EXCEPTION MATCH>Exception
None<EXCEPTION MATCH>Exception
NTLM_AUTH_NONE = 1
NTLM_AUTH_CONNECT = 2
NTLM_AUTH_CALL = 3
NTLM_AUTH_PKT = 4
NTLM_AUTH_PKT_INTEGRITY = 5
NTLM_AUTH_PKT_PRIVACY = 6
NTLMSSP_KEY_56 = 0x80000000L
NTLMSSP_KEY_EXCHANGE = 1073741824
NTLMSSP_KEY_128 = 536870912
NTLMSSP_TARGET_INFO = 8388608
NTLMSSP_NTLM2_KEY = 524288
NTLMSSP_CHALL_NOT_NT = 262144
NTLMSSP_CHALL_ACCEPT = 131072
NTLMSSP_CHALL_INIT = 65536
NTLMSSP_ALWAYS_SIGN = 32768
NTLMSSP_LOCAL_CALL = 16384
NTLMSSP_WORKSTATION = 8192
NTLMSSP_DOMAIN = 4096
NTLMSSP_NTLM_KEY = 512
NTLMSSP_NETWARE = 256
NTLMSSP_LM_KEY = 128
NTLMSSP_DATAGRAM = 64
NTLMSSP_SEAL = 32
NTLMSSP_SIGN = 16
NTLMSSP_TARGET = 4
NTLMSSP_OEM = 2
NTLMSSP_UNICODE = 1
class NTLMAuthHeader(Structure):
commonHdr = (('auth_type', 'B=10'), ('auth_level', 'B'), ('auth_pad_len', 'B=0'), ('auth_rsvrd', '"\x00'), ('auth_ctx_id', '<L=747920'))
structure = (('data', ':'),)
class NTLMAuthNegotiate(NTLMAuthHeader):
structure = (('', '"NTLMSSP\x00'), ('message_type', '<L=1'), ('flags', '<L'), ('domain_len', '<H-domain_name'), ('domain_max_len', '<H-domain_name'), ('domain_offset', '<L'), ('host_len', '<H-host_name'), ('host_maxlen', '<H-host_name'), ('host_offset', '<L'), ('host_name', ':'), ('domain_name', ':'))
def __init__(self):
NTLMAuthHeader.__init__(self)
self['flags'] = NTLMSSP_KEY_128 | NTLMSSP_KEY_EXCHANGE | NTLMSSP_NTLM_KEY | NTLMSSP_UNICODE | NTLMSSP_SIGN | NTLMSSP_SEAL | 0
self['host_name'] = ''
self['domain_name'] = ''
def __str__(self):
self['host_offset'] = 32
self['domain_offset'] = 32 + len(self['host_name'])
return NTLMAuthHeader.__str__(self)
class NTLMAuthChallenge(NTLMAuthHeader):
structure = (('', '"NTLMSSP\x00'), ('message_type', '<L=2'), ('domain_len', '<H-domain_name'), ('domain_max_len', '<H-domain_name'), ('domain_offset', '<L'), ('flags', '<L'), ('challenge', '8s'), ('reserved', '"\x00\x00\x00\x00\x00\x00\x00\x00'), ('domain_name', ':'))
class NTLMAuthChallengeResponse(NTLMAuthHeader):
structure = (('', '"NTLMSSP\x00'), ('message_type', '<L=3'), ('lanman_len', '<H-lanman'), ('lanman_max_len', '<H-lanman'), ('lanman_offset', '<L'), ('ntlm_len', '<H-ntlm'), ('ntlm_max_len', '<H-ntlm'), ('ntlm_offset', '<L'), ('domain_len', '<H-domain_name'), ('domain_max_len', '<H-domain_name'), ('domain_offset', '<L'), ('user_len', '<H-user_name'), ('user_max_len', '<H-user_name'), ('user_offset', '<L'), ('host_len', '<H-host_name'), ('host_max_len', '<H-host_name'), ('host_offset', '<L'), ('session_key_len', '<H-session_key'), ('session_key_max_len', '<H-session_key'), ('session_key_offset', '<L'), ('flags', '<L'), ('domain_name', ':'), ('user_name', ':'), ('host_name', ':'), ('lanman', ':'), ('ntlm', ':'), ('session_key', ':'))
def __init__(self, username, password, challenge):
NTLMAuthHeader.__init__(self)
self['session_key'] = ''
self['user_name'] = username.encode('utf-16le')
self['domain_name'] = ''
self['host_name'] = ''
self['flags'] = NTLMSSP_KEY_128 | NTLMSSP_KEY_EXCHANGE | NTLMSSP_NTLM_KEY | NTLMSSP_UNICODE | NTLMSSP_SIGN | NTLMSSP_SEAL | 0
if username and password:
lmhash = compute_lmhash(password)
nthash = compute_nthash(password)
self['lanman'] = get_ntlmv1_response(lmhash, challenge)
self['ntlm'] = get_ntlmv1_response(nthash, challenge)
else:
self['lanman'] = ''
self['ntlm'] = ''
if not self['host_name']:
self['host_name'] = 'NULL'.encode('utf-16le')
def __str__(self):
self['domain_offset'] = 64
self['user_offset'] = 64 + len(self['domain_name'])
self['host_offset'] = self['user_offset'] + len(self['user_name'])
self['lanman_offset'] = self['host_offset'] + len(self['host_name'])
self['ntlm_offset'] = self['lanman_offset'] + len(self['lanman'])
self['session_key_offset'] = self['ntlm_offset'] + len(self['ntlm'])
return NTLMAuthHeader.__str__(self)
class ImpacketStructure(Structure):
def set_parent(self, other):
self.parent = other
def get_packet(self):
return str(self)
def get_size(self):
return len(self)
class NTLMAuthVerifier(NTLMAuthHeader):
structure = (('version', '<L=1'), ('data', '12s'))
KNOWN_DES_INPUT = 'KGS!@#$%'
def __expand_DES_key(key):
key = key[:7]
key += '\x00' * (7 - len(key))
s = chr((ord(key[0]) >> 1 & 127) << 1)
s = s + chr(((ord(key[0]) & 1) << 6 | ord(key[1]) >> 2 & 63) << 1)
s = s + chr(((ord(key[1]) & 3) << 5 | ord(key[2]) >> 3 & 31) << 1)
s = s + chr(((ord(key[2]) & 7) << 4 | ord(key[3]) >> 4 & 15) << 1)
s = s + chr(((ord(key[3]) & 15) << 3 | ord(key[4]) >> 5 & 7) << 1)
s = s + chr(((ord(key[4]) & 31) << 2 | ord(key[5]) >> 6 & 3) << 1)
s = s + chr(((ord(key[5]) & 63) << 1 | ord(key[6]) >> 7 & 1) << 1)
s = s + chr((ord(key[6]) & 127) << 1)
return s
def __DES_block(key, msg):
if POW:
cipher = POW.Symmetric(POW.DES_ECB)
cipher.encryptInit(__expand_DES_key(key))
return cipher.update(msg)
else:
cipher = DES.new(__expand_DES_key(key), DES.MODE_ECB)
return cipher.encrypt(msg)
def ntlmssp_DES_encrypt(key, challenge):
answer = __DES_block(key[:7], challenge)
answer += __DES_block(key[7:14], challenge)
answer += __DES_block(key[14:], challenge)
return answer
def compute_lmhash(password):
password = password.upper()
lmhash = __DES_block(password[:7], KNOWN_DES_INPUT)
lmhash += __DES_block(password[7:14], KNOWN_DES_INPUT)
return lmhash
def compute_nthash(password):
password = unicode(password).encode('utf_16le')
if POW:
hash = POW.Digest(POW.MD4_DIGEST)
else:
hash = MD4.new()
hash.update(password)
return hash.digest()
def get_ntlmv1_response(key, challenge):
return ntlmssp_DES_encrypt(key, challenge)